<?php
namespace app\models;
use common\component\tool\Tool;
use app\models\Basic;

use Yii;

class TagsRelationships extends Basic
{
    
    public static function tableName()
    {
        return '{{%tags_relationships}}';
    }

    public function rules()
    {
        return [
            ['app_id', 'required', 'message' => 'app_id不能为空', 'on' => 'add'],
            ['app_id', 'integer', 'message' => 'app_id必须为数字，或数字字符串', 
                        'min'=>0, 'tooSmall' => 'app_id最小存储0', 
                        'max'=>18446744073709551615, 'tooBig' => 'app_id最大存储18446744073709551615'],
            ['unionid', 'required', 'message' => 'unionid不能为空'],
            ['unionid', 'integer', 'message' => 'unionid必须为数字，或数字字符串', 
                        'min'=>0, 'tooSmall' => 'unionid最小存储0', 
                        'max'=>18446744073709551615, 'tooBig' => 'unionid最大存储18446744073709551615'],
            ['tid', 'required', 'message' => 'tid不能为空'],
            ['tid', 'integer', 'message' => 'tid必须为数字，或数字字符串', 
                        'min'=>0, 'tooSmall' => 'tid最小存储0', 
                        'max'=>18446744073709551615, 'tooBig' => 'tid最大存储18446744073709551615'],
            ['flag', 'integer', 'message' => 'flag必须为数字，或数字字符串', 
                     'min'=>0, 'tooSmall' => 'flag最小存储0', 
                     'max'=>255, 'tooBig' => 'flag最大存储255'],
        ];
    }


    /*添加*/
    public function addRelationships($data, $app_id)
    {
        $data['TagsRelationships']['app_id'] = $app_id;
        // P($data);
        if($this->load($data) and $this->validate()){
            // P($this);
            if($this->save(false)){
                return true;
            }
        }
        return false;
    }


    /*关联查询 标签*/
    public function getTag()
    {
        $tag = $this->hasOne(Tags::className(), ['tid' => 'tid'])->select(['tid', 'tag_name', 'heat']);
        return $tag;
    }

    
}